package world;
import gui.Camera;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;

public class Platform extends JLabel
{
	private int x, y;
	private int tilesWide;
	private int tilesHigh;
	private BufferedImage bimg;
	
	public Platform(ImageIcon icon, int x, int y,int tilesWide, int tilesHigh)
	{
		this.x = x;
		this.y = y;
		this.tilesWide = tilesWide;
		this.tilesHigh = tilesHigh;
		
		setupBimg(icon);
		setupJLabel();
	}
	
	private void setupJLabel() 
	{
		setSize(bimg.getWidth(), bimg.getHeight());
		setIcon(new ImageIcon(bimg));
	
		setBorder(new LineBorder(Color.BLACK));
	}

	private void setupBimg(ImageIcon icon)
	{
		int pixelsWide = icon.getIconWidth() * tilesWide;
		int pixelsHigh = icon.getIconHeight() * tilesHigh;
	
		bimg = new BufferedImage(pixelsWide, pixelsHigh, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = bimg.createGraphics();
		
		for(int tileX = 0; tileX < pixelsWide; tileX += icon.getIconWidth()) {
			for(int tileY = 0; tileY < pixelsHigh; tileY += icon.getIconHeight()) {
				g.drawImage(icon.getImage(), tileX, tileY, null);
			}
		}
	}
	
	public void render(Camera cam)
	{
		int locX = x - cam.getX();
		int locY = y - cam.getY();
		
		setLocation(locX, locY);
	}
}
